// create by lwy 2017年9月28日14:23:23
var shopId = '';
$(function () {
    doAjax();
})

function doAjax() {
    $.ajax({
        url:'/zuoDanC/userOrderDetail.json',
        dataType:'json',
        data:{
            token:getItem('token'),
            zuoDanId:GetQueryString('zuoDanId'),
        },
        type:'post',
        success:function (data) {
            if(data.code==1){
                var orderData = data.datas.orderDetail
                $('.state').html(orderData.state);
                $('.name').html(orderData.name);
                $('.phone').html(orderData.phone);
                $('.address_detail').html(orderData.province+orderData.city+orderData.county+orderData.addressDetail)
                $('.shopName').html(orderData.shopName);
                shopId = orderData.shopId;
                var goodsData = orderData.goodsOrderList;
                var ifCash = '';
                if(data.payOnDelivery==0){
                    ifCash = '<span class="payCash">货到付款</span>'
                }else{
                    ifCash = ''
                }
                for(var i=0;i<goodsData.length;i++){
                    $('<div class="mui-clearfix goods_de" goodsId="'+goodsData[i].goodsId+'">\n' +
                        '<div class="goods-img-box">\n' +
                        '<img src="'+goodsData[i].picture+'">\n' +
                        '</div>\n' +
                        '<div class="goods-product-box">\n' +
                        '<p class="goodsName">'+ifCash+goodsData[i].goodsName+'</p>\n' +
                        '<span class="guige">'+goodsData[i].goodsSpecification+'</span><span class="price">￥'+goodsData[i].salePrice+'<i>×'+goodsData[i].num+'</i></span>\n' +
                        '</div>\n' +
                        '</div>').appendTo($('#OrderBox1'));
                }
                $('.total_count').html('共'+goodsData.length+'件商品');
                $('#money').html('¥ '+orderData.z_shopYingYeMoney);
                $('.order_code').html('订单编号：'+orderData.z_code);
                $('<div>创建时间：'+orderData.createTime+'</div>').appendTo($('.order_info'))
                if(orderData.stateValue==8){
                    $('<div>取消时间：'+orderData.cancelTime+'</div>').appendTo($('.order_info'))
                }
                if(orderData.stateValue==5||orderData.stateValue==6||orderData.stateValue==2){
                    $('<div>发货时间：'+orderData.deliverTime+'</div>').appendTo($('.order_info'))
                }
            }
        }
    })
}

$('body').on('click','.shopName',function () {
    window.location.href="shop_v2.html?shopId="+shopId;
})

$('body').on('click','.goods_de',function () {
    var goodsId = $(this).attr('goodsId');
    window.location.href="goods_v2.html?goodsId="+goodsId+"&shopId="+shopId;
})
